import '../utils/tools.dart';
import 'comparable.dart';
import 'serializable.dart';

class FeedbackModel extends Serializable implements Equable<int> {
  int id = 0;
  int memberId = 0;
  String realName = '';
  String mobile = '';
  String email = '';
  int type = 0;
  int createTime = 0;
  int updateTime = 0;
  String ip = '';
  int status = 0;
  String content = '';
  String reply = '';
  int managerId = 0;
  int replyTime = 0;

  bool _isSubmit = false;

  FeedbackModel({
    this.memberId = 0,
    this.realName = '',
    this.mobile = '',
    this.email = '',
    this.type = 0,
    this.content = '',
  }) : _isSubmit = true;

  FeedbackModel.fromJson(Map? model) {
    if (model == null) return;
    id = Tools.parseInt(model['id']);
    memberId = Tools.parseInt(model['member_id']);

    realName = model['realname'] ?? '';
    mobile = model['mobile'] ?? '';
    email = model['email'] ?? '';

    type = Tools.parseInt(model['type']);
    createTime = Tools.parseInt(model['create_time']);
    updateTime = Tools.parseInt(model['update_time']);

    ip = model['ip'] ?? '';

    status = Tools.parseInt(model['id']);

    content = model['content'] ?? '';
    reply = model['reply'] ?? '';

    managerId = Tools.parseInt(model['manager_id']);
    replyTime = Tools.parseInt(model['reply_time']);
  }

  @override
  Map<String, dynamic> toJson() {
    Map<String, Object> jsonObj = {};
    jsonObj['member_id'] = memberId;
    jsonObj['realname'] = realName;
    jsonObj['mobile'] = mobile;
    jsonObj['email'] = email;
    jsonObj['type'] = type;
    jsonObj['content'] = content;
    if (!_isSubmit) {
      jsonObj['id'] = id;
      jsonObj['create_time'] = createTime;
      jsonObj['update_time'] = updateTime;
      jsonObj['ip'] = ip;
      jsonObj['status'] = status;
      jsonObj['reply'] = reply;
      jsonObj['manager_id'] = managerId;
      jsonObj['reply_time'] = replyTime;
    }
    return jsonObj;
  }

  @override
  int get compareField => id;
}
